#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :get_chapter_num.py
# @Time      :2023/10/17 
# @Author    :CL
# @email     :1037654919@qq.com
#基于bookid获取章节信息
import requests
import json
def get_chapter_num(bookId='26797244'):
    print('begin get_chapter_num:', bookId)
    headers = {
        "authority": "weread.qq.com",
        "accept": "application/json, text/plain, */*",
        "accept-language": "zh-CN,zh;q=0.9",
        "content-type": "application/json;charset=UTF-8",
        "origin": "https://weread.qq.com",
        "referer": "https://weread.qq.com/web/reader/223320f0813ab81afg018f12ka87322c014a87ff679a21ea",
        "sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Linux\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
    }
    cookies = {
        "qq_domain_video_guid_verify": "b9f5e2164847a357",
        "pgv_pvid": "3380599040",
        "fqm_pvqid": "bbafb710-8487-4c50-897c-0c9a5a43eddb",
        "RK": "AT2N+qJJSD",
        "ptcz": "c0dba204eb3ed47316a75aa89b318ce1ebfd84aa70c620a582419ea7bb6e090e",
        "tmeLoginType": "2",
        "psrf_qqopenid": "07B848438A1DF5D6FBFA931D2CDFD036",
        "psrf_qqunionid": "73F2F591EF6BBB07004184D7E0024E86",
        "psrf_qqrefresh_token": "EFB86C3BB6541BFB0424C5215F1D2A90",
        "psrf_access_token_expiresAt": "1698199558",
        "euin": "oKni7iCk7eE5Nv**",
        "wxrefresh_token": "",
        "uin": "1037654919",
        "psrf_qqaccess_token": "AF150CB8C6BAD8AC4C84D6C206FB2D68",
        "wxopenid": "",
        "wxunionid": "",
        "wr_fp": "1600462502",
        "wr_gid": "247667256",
        "wr_theme": "white",
        "wr_localvid": "",
        "wr_name": "",
        "wr_avatar": "",
        "wr_gender": ""
    }
    url = "https://weread.qq.com/web/book/publicchapterInfos"
    data = {
        "bookIds": [
            bookId
        ]
    }
    data = json.dumps(data, separators=(',', ':'))
    response = requests.post(url, headers=headers, cookies=cookies, data=data)
    json_data = json.loads(response.text)
    updated = json_data["data"][0]["updated"]
    return updated

if __name__ == "__main__":
    print()
    cha =get_chapter_num()
    print(cha)
